<template>
  <el-dialog
    title="企业详情"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
    <el-form-item label="企业名称" prop="enterpriseName">
      <el-input :value="dataForm.enterpriseName" placeholder="企业名称"></el-input>
    </el-form-item>
    <el-form-item label="证件号" prop="cardId">
      <el-input :value="dataForm.cardId" placeholder="证件号"></el-input>
    </el-form-item>
    <el-form-item label="证照有效日期" prop="cardAlidTime">
      <el-input :value="dataForm.cardAlidTime" placeholder="证照有效日期"></el-input>
    </el-form-item>
    <el-form-item label="注册地址" prop="registerAddress">
      <el-input :value="dataForm.registerAddress" placeholder="注册地址"></el-input>
    </el-form-item>
    <el-form-item label="法人姓名" prop="legalPerson">
      <el-input :value="dataForm.legalPerson" placeholder="法人姓名"></el-input>
    </el-form-item>
    <!-- <el-form-item label="法人证件类型" prop="legalCardType">
      <el-input v-model="dataForm.legalCardType" placeholder="法人证件类型"></el-input>
    </el-form-item> -->
    <el-form-item label="法人证件号" prop="legalCardId">
      <el-input :value="dataForm.legalCardId" placeholder="法人证件号"></el-input>
    </el-form-item>
    <el-form-item label="公司联系电话" prop="photoNumber">
      <el-input :value="dataForm.photoNumber" placeholder="公司联系电话"></el-input>
    </el-form-item>
    <el-form-item label="公司邮箱" prop="email">
      <el-input :value="dataForm.email" placeholder="公司邮箱"></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="contactsName">
      <el-input :value="dataForm.contactsName" placeholder="联系人"></el-input>
    </el-form-item>
    <el-form-item label="联系人电话" prop="contactsPhoto">
      <el-input :value="dataForm.contactsPhoto" placeholder="联系人电话"></el-input>
    </el-form-item>
    <el-form-item label="联系人邮箱" prop="contactsEmail">
      <el-input :value="dataForm.contactsEmail" placeholder="联系人邮箱"></el-input>
    </el-form-item>
    <!-- <el-form-item label="营业执照，社会统一信用代码证" prop="licenseFile">
      <el-input v-model="dataForm.licenseFile" placeholder="营业执照，社会统一信用代码证"></el-input>
    </el-form-item> -->
    <el-form-item label="审批状态" prop="state">
      <el-switch v-model="dataForm.state" active-text="通过" active-value="通过" inactive-text="不通过" inactive-value="不通过" @change="changeState"></el-switch>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          enterpriseName: '',
          cardId: '',
          cardAlidTime: '',
          registerAddress: '',
          legalPerson: '',
          legalCardType: '',
          legalCardId: '',
          photoNumber: '',
          email: '',
          contactsName: '',
          contactsPhoto: '',
          contactsEmail: '',
          licenseFile: '',
          state: ''
        },
        dataRule: {
          /*enterpriseName: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          cardId: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          cardAlidTime: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          registerAddress: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          legalPerson: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          legalCardType: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          legalCardId: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          photoNumber: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          email: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          contactsName: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          contactsPhoto: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          contactsEmail: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          licenseFile: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          createPersonId: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          createPersonName: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          updatePersonId: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          updatePersonName: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          deleteTime: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          deletePersonId: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          deletePersonName: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          state: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ],
          deleteFlag: [
            { required: true, message: '请输入不能为空', trigger: 'blur' }
          ]*/
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/authentication/authenticationenterprise/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.enterpriseName = data.authenticationEnterprise.enterpriseName
                this.dataForm.cardId = data.authenticationEnterprise.cardId
                this.dataForm.cardAlidTime = data.authenticationEnterprise.cardAlidTime
                this.dataForm.registerAddress = data.authenticationEnterprise.registerAddress
                this.dataForm.legalPerson = data.authenticationEnterprise.legalPerson
                this.dataForm.legalCardType = data.authenticationEnterprise.legalCardType
                this.dataForm.legalCardId = data.authenticationEnterprise.legalCardId
                this.dataForm.photoNumber = data.authenticationEnterprise.photoNumber
                this.dataForm.email = data.authenticationEnterprise.email
                this.dataForm.contactsName = data.authenticationEnterprise.contactsName
                this.dataForm.contactsPhoto = data.authenticationEnterprise.contactsPhoto
                this.dataForm.contactsEmail = data.authenticationEnterprise.contactsEmail
                this.dataForm.licenseFile = data.authenticationEnterprise.licenseFile
                this.dataForm.createTime = data.authenticationEnterprise.createTime
                this.dataForm.createPersonId = data.authenticationEnterprise.createPersonId
                this.dataForm.createPersonName = data.authenticationEnterprise.createPersonName
                this.dataForm.updateTime = data.authenticationEnterprise.updateTime
                this.dataForm.updatePersonId = data.authenticationEnterprise.updatePersonId
                this.dataForm.updatePersonName = data.authenticationEnterprise.updatePersonName
                this.dataForm.deleteTime = data.authenticationEnterprise.deleteTime
                this.dataForm.deletePersonId = data.authenticationEnterprise.deletePersonId
                this.dataForm.deletePersonName = data.authenticationEnterprise.deletePersonName
                this.dataForm.state = data.authenticationEnterprise.state == '0'
                this.dataForm.deleteFlag = data.authenticationEnterprise.deleteFlag
              }
            })
          }
        })
      },
      changeState: function (state) {
        this.dataForm.state = state
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/authentication/authenticationenterprise/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'state': this.dataForm.state ? '0' : '1'
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
